/*
 * LocalFilePropertiesFrame.java
 *
 * Created on 21/12/2011, 22:19:56
 */

package br.mg.bhe.ftpobre.gui.fs;

import java.io.File;

import br.mg.bhe.ftpobre.fs.LocalFile;
import br.mg.bhe.ftpobre.util.DateConverter;
import br.mg.bhe.ftpobre.util.FileSizeConverter;
import br.mg.bhe.ftpobre.util.LocalFileUtil;

/**
 *
 * @author Aureliano
 */
public class LocalFilePropertiesFrame extends javax.swing.JDialog {

    /** Creates new form LocalFilePropertiesFrame */
    public LocalFilePropertiesFrame(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        LocalFile file = this.getSelectedLocalFile();
        this.loadData(file);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelName = new javax.swing.JLabel();
        textFieldName = new javax.swing.JTextField();
        labelPath = new javax.swing.JLabel();
        textFieldPath = new javax.swing.JTextField();
        labelSize = new javax.swing.JLabel();
        labelLastModified = new javax.swing.JLabel();
        labelCanRead = new javax.swing.JLabel();
        labelCanWrite = new javax.swing.JLabel();
        labelIsAbsolute = new javax.swing.JLabel();
        labelFolder = new javax.swing.JLabel();
        labelFile = new javax.swing.JLabel();
        labelHidden = new javax.swing.JLabel();
        labelSizeValue = new javax.swing.JLabel();
        labelLastModifiedValue = new javax.swing.JLabel();
        labelCanReadValue = new javax.swing.JLabel();
        labelCanWriteValue = new javax.swing.JLabel();
        labelIsAbsoluteValue = new javax.swing.JLabel();
        labelFolderValue = new javax.swing.JLabel();
        labelFileValue = new javax.swing.JLabel();
        labelHiddenValue = new javax.swing.JLabel();
        buttonConfirm = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Propriedades");
        setResizable(false);

        labelName.setText("Nome:");

        textFieldName.setEditable(false);

        labelPath.setText("Caminho:");

        textFieldPath.setEditable(false);

        labelSize.setText("Tamanho:");

        labelLastModified.setText("Última modificação:");

        labelCanRead.setText("Pode ler:");

        labelCanWrite.setText("Pode escrever:");

        labelIsAbsolute.setText("Absoluto:");

        labelFolder.setText("Pasta:");

        labelFile.setText("Arquivo:");

        labelHidden.setText("Oculto:");

        labelSizeValue.setText("...");

        labelLastModifiedValue.setText("...");

        labelCanReadValue.setText("...");

        labelCanWriteValue.setText("...");

        labelIsAbsoluteValue.setText("...");

        labelFolderValue.setText("...");

        labelFileValue.setText("...");

        labelHiddenValue.setText("...");

        buttonConfirm.setText("OK");
        buttonConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonConfirmActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelHidden)
                            .addComponent(labelFile)
                            .addComponent(labelIsAbsolute)
                            .addComponent(labelFolder))
                        .addGap(64, 64, 64))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelName)
                            .addComponent(labelPath)
                            .addComponent(labelSize)
                            .addComponent(labelLastModified)
                            .addComponent(labelCanRead)
                            .addComponent(labelCanWrite))
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelCanReadValue)
                            .addComponent(labelSizeValue)
                            .addComponent(labelLastModifiedValue)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(labelFolderValue)
                                    .addComponent(labelIsAbsoluteValue)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(1, 1, 1)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(labelHiddenValue)
                                            .addComponent(labelFileValue))))
                                .addComponent(labelCanWriteValue))
                            .addComponent(textFieldName, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                            .addComponent(textFieldPath, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)))
                    .addComponent(buttonConfirm, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelPath))
                .addGap(8, 8, 8)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelSize)
                    .addComponent(labelSizeValue))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelLastModifiedValue)
                    .addComponent(labelLastModified))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelCanRead)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelCanWrite)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelIsAbsolute)
                        .addGap(13, 13, 13)
                        .addComponent(labelFolder)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelFile)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelHidden))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(labelCanReadValue)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelCanWriteValue)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelIsAbsoluteValue)
                        .addGap(13, 13, 13)
                        .addComponent(labelFolderValue)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelFileValue)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelHiddenValue)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addComponent(buttonConfirm)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-505)/2, (screenSize.height-363)/2, 505, 363);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfirmActionPerformed
        super.dispose();
    }//GEN-LAST:event_buttonConfirmActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonConfirm;
    private javax.swing.JLabel labelCanRead;
    private javax.swing.JLabel labelCanReadValue;
    private javax.swing.JLabel labelCanWrite;
    private javax.swing.JLabel labelCanWriteValue;
    private javax.swing.JLabel labelFile;
    private javax.swing.JLabel labelFileValue;
    private javax.swing.JLabel labelFolder;
    private javax.swing.JLabel labelFolderValue;
    private javax.swing.JLabel labelHidden;
    private javax.swing.JLabel labelHiddenValue;
    private javax.swing.JLabel labelIsAbsolute;
    private javax.swing.JLabel labelIsAbsoluteValue;
    private javax.swing.JLabel labelLastModified;
    private javax.swing.JLabel labelLastModifiedValue;
    private javax.swing.JLabel labelName;
    private javax.swing.JLabel labelPath;
    private javax.swing.JLabel labelSize;
    private javax.swing.JLabel labelSizeValue;
    private javax.swing.JTextField textFieldName;
    private javax.swing.JTextField textFieldPath;
    // End of variables declaration//GEN-END:variables
	
	private void loadData(LocalFile file) {
		File f = new File(file.getPath());
		textFieldName.setText(f.getName());
		textFieldPath.setText(f.getAbsolutePath());
		labelSizeValue.setText(FileSizeConverter.convertFileSize(f.length()));
		labelLastModifiedValue.setText(DateConverter.convert(f.lastModified()));
		labelCanReadValue.setText((f.canRead()) ? "Sim" : "Não");
		labelCanWriteValue.setText((f.canWrite()) ? "Sim" :"Não");
		labelIsAbsoluteValue.setText((f.isAbsolute()) ? "Sim" : "Não");
		labelFolderValue.setText((f.isDirectory()) ? "Sim" : "Não");
		labelFileValue.setText((f.isFile()) ? "Sim" : "Não");
		labelHiddenValue.setText((f.isHidden()) ? "Sim" : "Não");
	}
	
	private LocalFile getSelectedLocalFile() {
		LocalFile file = LocalFileUtil.getSelectedFile();
		if (file == null) {
			throw new RuntimeException(
					"Não foi possível recuperar o arquivo selecionado da relação de arquivos locais.");
		}
		
		return file;
	}
}